package com.twu.biblioteca;

/**
 * Created by IntelliJ IDEA.
 * User: dixithk
 * Date: 6/18/14
 * Time: 2:36 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReturnBook implements MenuOperations {

    UserInterface ui = new UserInterfaceApp();
    Library lib = new Library();

    public ReturnBook(UserInterface Ui , Library lib)
    {
        this.ui = Ui;
        this.lib = lib;

    }
    @Override
    public Result action() {

        Book BookNeedToBeReturned = lib.GiveBookObjectFromTitle(ui.takeInputFromUserForReturn());
                     if(BookNeedToBeReturned!=null && (lib.isAvailableForCheckOut(BookNeedToBeReturned)))
                     {


                             BookNeedToBeReturned.markAsReturned();
                            return new Result("Thank you for returning the book." , true);

                     }
                     else
                     {
                         return new Result("That is not a valid book to return." , false);
                     }




    }

    @Override
    public String getName() {
        return "Return Book";  //To change body of implemented methods use File | Settings | File Templates.
    }
}
